package com.boang.state;

import java.util.concurrent.locks.LockSupport;

/*
    @author:sa
    @date:2024/11/27 9:53
*/
public class ThreadStateWaitDemo02 {
    public static void main(String[] args) {
        Object lock=new Object();
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized (lock) {
                    try {
                        lock.notify();
                        lock.wait();
                        LockSupport.park();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
                System.out.println("abc");
            }
        }).start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (lock) {
                    try {
                        lock.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
                System.out.println("def");
            }
        }).start();
        for (int i = 0; i < 100; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        Thread.sleep(3000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    System.out.println("abc");
                }
            }).start();
        }
    }
}